using dnAnalytics.LinearAlgebra.Solvers;

namespace dnAnalytics.Examples.LinearAlgebra.Solvers
{
    /// <summary>
    /// Provides an example of the creation of the convergence monitor
    /// </summary>
    public sealed class ConvergenceMonitorConstructor
    {
        /// <summary>
        /// Creates a convergence monitor.
        /// </summary>
        public void CreateMonitor()
        {
            // Set the maximum number of iterations that the convergence monitor
            // will allow before indicating that the iteration must be stopped.
            int maximumNumberOfIterations = 10;

            // Set the value the residual must maximally have before the 
            // convergence monitor will declare that the iteration has converged.
            // Note that this residual is relative to the starting point which is
            // determined by the matrix norm.
            double minimumResidual = 1E-5;

            // Set the matrix norm. This will be used by the convergence monitor
            // to get a base line for the convergence limit.
            double matrixNorm = 10;

            // Finally create the convergence monitor with the values
            // we have defined above
            ConvergenceMonitor monitor = new ConvergenceMonitor(maximumNumberOfIterations,
                                                                minimumResidual,
                                                                matrixNorm);
        }
    }
}